#!/bin/sh

cd /tmp
echo "Downloading the NSLU2_V23R63.zip firmware ...."
if [ ! -f NSLU2_V23R63.zip ] ; then
  wget 'http://www.linksys.com/servlet/Satellite?blobcol=urldata&blobheadername1=Content-Type&blobheadername2=Content-Disposition&blobheadervalue1=application%2Fzip&blobheadervalue2=inline%3B+filename%3DNSLU2_V23R63.zip&blobkey=id&blobtable=MungoBlobs&blobwhere=1124848568017&ssbinary=true' -O NSLU2_V23R63.zip
fi
if [ "`md5sum < NSLU2_V23R63.zip`" != "423f65fb2121bbf9855d060dce29b3af  -" ] ; then
  echo "ERROR: The download from www.linksys.com has failed."
  echo "Please download the NSLU2_V23R63.zip firmware manually into /tmp and try again."
  exit 1
fi
echo "Extracting the firmware binary ..."
/opt/bin/unzip -o NSLU2_V23R63.zip
echo "Extracting the ramdisk image ..."
dd if=NSLU2_V23R63.bin of=ramdisk.gz bs=16 skip=90113 count=288898
gunzip ramdisk.gz
echo "Extracting the ufsd kernel module ..."
/opt/bin/e2cp ramdisk:/lib/modules/ufsd.o /lib/modules/ufsd.o
/opt/bin/e2cp ramdisk:/lib/modules/ufsd.o /initrd/lib/modules/ufsd.o
echo "Cleaning up ..."
rm -rf NSLU2_V23R63.bin ramdisk ramdisk.gz
echo "Done."
